package com.vimi8.ebb.sqlprovider;


import com.vimi8.ebb.model.ElectricityBusiness;
import com.vimi8.ebb.model.ProductInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * Created by think on 2016/7/7.
 */
public class ProductInfoSqlProvider {
    private Logger logger =  LoggerFactory.getLogger(this.getClass());

    public String getInsertProductSql(Map<String, Object> parameters){
        StringBuilder sqlSb=new StringBuilder();
        List<ProductInfo> productInfoList=  ( List<ProductInfo>)parameters.get("productInfoList");
        sqlSb.append("INSERT INTO product_info(id,business_volume,trading_volume,sales_area,product_name,enum_category_id,unit_price,electricity_business_id,stock_volume,stock_unit,trading_time) VALUES");
        int count=0;
        for(ProductInfo productInfo:productInfoList){
            sqlSb.append("('");
            sqlSb.append(productInfo.getId()+"','");
            sqlSb.append(productInfo.getBusinessVolume()+"','");
            sqlSb.append(productInfo.getTradingVolume()+"','");
            sqlSb.append(productInfo.getSalesArea()+"','");
            sqlSb.append(productInfo.getProductName()+"','");
            sqlSb.append(productInfo.getEnumCategoryId()+"','");
            sqlSb.append(productInfo.getUnitPrice()+"','");
            sqlSb.append(productInfo.getElectricityBusinessId()+"','");
            sqlSb.append(productInfo.getStockVolume()+"','");
            sqlSb.append(productInfo.getStockUnit()+"','");
            sqlSb.append(productInfo.getTradingTime()+"'");

            if(productInfoList.size()-1>count){
                sqlSb.append("),");
            }else{
                sqlSb.append(");");
            }

            count++;
        }
        logger.info("sqlStr="+sqlSb.toString());
        return sqlSb.toString();
    }
    //getInsertTrainInfoSql


}
